package cz.zcu.fav.rat.managed.bean.calendar;

import java.util.List;

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;

import cz.zcu.fav.rat.beans.Period;
import cz.zcu.fav.rat.beans.User;

@ManagedBean(name = "userCalendarBean")
@ViewScoped
public class UserCalendarBean extends MyCalendarBean
{
	private static final long serialVersionUID = -9178294158186777650L;
	private List<User> users;
	
	
	public List<User> getUsers()
	{
		return users;
	}

	@Override
	@PostConstruct
	public void init()
	{
		super.init();
		users = getUserService().getAll();
	}

	protected Integer loadIdentifier()
	{
		String userIdAsString = FacesContext.getCurrentInstance()
				.getExternalContext().getRequestParameterMap().get("id");
		try
		{
			return Integer.valueOf(userIdAsString);
		} catch (NumberFormatException ex)
		{
			return null;
		}
	}
	
	public void pickUpEvent(ActionEvent actionEvent)
	{
		Period period = getPeriodService().pickUp(
				getEvent().getObject().getId(), getItem());
		if (period != null)
		{
			if (!period.getReservation().getUser().equals(getItem()))
			{
				// this is not my reservation
				// TODO: notify somehow
			} else
			{
				// /fine
				// TODO: notify somehow
			}
		} else
		{
			System.out.print("sdfsdf");
			// TODO: notify somehow

			// nic nebylo picknutý

		}
	}
}
